package com.nd.android.musicboxlibrary.util.fastDateUtil;

import java.util.Calendar;

/**
 * <p>
 * Inner class to output the twenty four hour field.
 * </p>
 */
public class TwentyFourHourField implements NumberRule {
    private final NumberRule mRule;

    /**
     * Constructs an instance of <code>TwentyFourHourField</code> with the specified
     * <code>NumberRule</code>.
     * 
     * @param rule
     *            the rule
     */
    public TwentyFourHourField(NumberRule rule) {
        mRule = rule;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int estimateLength() {
        return mRule.estimateLength();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void appendTo(StringBuffer buffer, Calendar calendar) {
        int value = calendar.get(Calendar.HOUR_OF_DAY);
        if (value == 0) {
            value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;
        }
        mRule.appendTo(buffer, value);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void appendTo(StringBuffer buffer, int value) {
        mRule.appendTo(buffer, value);
    }
}
